package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.CustomerFollowRecord;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.QueryObject;
import trlygjj.tanruiliyigenjinjin.service.ICustomerFollowRecordService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("customerFollowRecord")
public class CustomerFollowRecordController {

    @Autowired
    private ICustomerFollowRecordService customerFollowRecordService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     *
     * @return
     */
    @RequestMapping("")
    public String index() {
        return "customerFollowRecord/list";
    }

    /**
     * 具有分页和高级查询
     *
     * @return
     */
    @RequestMapping("list")
    @RequiresPermissions("customerFollowRecord:list")
    @PermissionName("客户跟踪列表")
    @ResponseBody
    public PageResult list(QueryObject qo) {
        PageResult result = customerFollowRecordService.query(qo);
        return result;
    }

    /**
     * 查询全部
     *
     * @return
     */
    @RequestMapping("listAll")
    @ResponseBody
    public List<CustomerFollowRecord> listAll() {
        return customerFollowRecordService.selectAll();
    }

   /* *//**
     * 删除
     *
     * @param customerFollowRecordId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     *//*
    @RequestMapping("delete")
    @RequiresPermissions("customerFollowRecord:delete")
    @PermissionName("客户跟踪记录删除")
    @ResponseBody
    public JsonResult delete(Long customerFollowRecordId) {
        JsonResult result = new JsonResult();
        try {
            customerFollowRecordService.deleteByPrimaryKey(customerFollowRecordId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }*/

    /**
     *更新
     * @param customerFollowRecord 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     *//*
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(CustomerFollowRecord customerFollowRecord) {
        JsonResult result = new JsonResult();
        try {
            customerFollowRecordService.updateByPrimaryKey(customerFollowRecord);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }*/

    /**
     * 保存
     *
     * @param customerFollowRecord 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("save")
    @RequiresPermissions("customerFollowRecord:sava")
    @PermissionName("客户跟踪")
    @ResponseBody
    public JsonResult save(CustomerFollowRecord customerFollowRecord) {
        JsonResult result = new JsonResult();
        try {
            customerFollowRecordService.insert(customerFollowRecord);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 审核
     *
     * @param id 要审核的id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("audit")
    @RequiresPermissions("customerFollowRecord:audit")
    @PermissionName("客户跟踪记录审核")
    @ResponseBody
    public JsonResult audit(Long id) {
        JsonResult result = new JsonResult();
        try {
            customerFollowRecordService.audit(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }
}